#include <kb.h>
#include <common.h>

unsigned char shift = 0;
unsigned char ctrl = 0;

void keyboard_handler()
{
	unsigned char scancode;
	scancode = inportb(0x60);
	
	if (scancode & 0x80){
		if (scancode == 0x80+42)
		{
			shift = 0;
		}
		else if (scancode == 0x80+29)
		{
			ctrl = 0;
		}
	}
	else
	{
		if (scancode == 42) {
			shift = 1;
		}
		else if (scancode == 29)
		{
			ctrl = 1;
		}
		else
		{
			if (ctrl && scancode == 38) clear_screen();
			else if (shift) print_char(kbdus_upper[scancode]);
			else print_char(kbdus[scancode]);
		}
	}
}

void init_keyboard()
{
	irq_install_handler(1, keyboard_handler);
	print_OK();
}